package com.blog.controller;

import com.blog.common.CommonRespDto;
import com.blog.common.RespBean;
import com.blog.seckill.goods.Good;
import com.blog.service.GoodBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

/**
 * @ClassName GoodBaseController
 * @Destription Good基础：增删改查
 * @Author 天堂小野花
 * @Date 2025/8/19  19:16
 * @Version 1.0
 */
@RestController
@RequestMapping("/good")
public class GoodBaseController {
    @Autowired
    GoodBaseService goodBaseService;


    /**
     * @Author 天堂小野花
     * @Description 更新库存
     * @Date 20:53 2025/8/23
     * @Param [goodId, num]
     * @return com.blog.common.RespBean
     **/
    @PutMapping("/goodInventoryNumById")
    public int goodInventoryNumById(@RequestParam("goodId") Integer goodId, @RequestParam("num") Integer num){
        if(goodBaseService.goodInventoryNumById(goodId,num) == 1){
            return 1;
        }
        return 0;
    }
    @GetMapping("/selectAllGoods")
    public CommonRespDto selectAllGoods(){
        return CommonRespDto.success(goodBaseService.selectAllGoods());
    }
    @GetMapping("/base/selectGoodById/{rid}")
    public Good selectGoodById(@PathVariable Integer rid){
        return goodBaseService.selectGoodById(rid);
    }


    @PostMapping("/base/insertGood")
    public RespBean insertGood(@RequestBody Good good){
        if(goodBaseService.insertGood(good) == 1 ){
            return RespBean.ok("添加成功");
        }
        return RespBean.error("添加失败");
    }
    @DeleteMapping("/base/deleteRole/{rid}")
    public RespBean deleteRoleById(@PathVariable Integer rid){
        if(goodBaseService.deleteGoodById(rid) == 1){
            return RespBean.ok("删除成功");
        }
        return RespBean.error("删除失败");
    }
    @PutMapping("/base/updateGood")
    public RespBean updateGood(@RequestBody Good good){

        if(goodBaseService.updateGood(good) == 1){
            return RespBean.ok("更新成功");
        }
        return RespBean.error("更新失败");
    }
}
